package com.fy56.platform.logistics.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import org.omg.Messaging.SYNC_WITH_TRANSPORT;

import java.awt.*;
import java.util.*;
import java.util.List;

import static com.fy56.platform.logistics.utils.HttpUtil.setHeader;

public class test {
    public static void main(String args[]) {
        String a="`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id'," +
                "`companyId` int(11) NOT NULL COMMENT '企业ID'," +
                "`companyCode` varchar(100) NOT NULL COMMENT '企业编码'," +
                "`companyName` varchar(300) NOT NULL COMMENT '企业名称'," +
                "`parentId` int(11) DEFAULT '0' COMMENT '父级公司ID'," +
                "`parentIds` text COMMENT '所有父级编号'," +
                "`mobile` varchar(100) DEFAULT NULL COMMENT '用户手机号'," +
                "`childNames` varchar(100) DEFAULT NULL COMMENT '网点分部'," +
                "`receivingBranch` varchar(100) DEFAULT NULL COMMENT '收获网点'," +
                "`headquartersLocation` varchar(100) DEFAULT NULL COMMENT '总部所在地'," +
                "`address` varchar(100) DEFAULT NULL COMMENT '联系地址'," +
                "`displayFlag` int(11) NOT NULL DEFAULT '0' COMMENT '是否可用 0:正常 1:停用'," +
                "`topCompanyId` int(11) DEFAULT '0' COMMENT '最顶级机构Id'," +
                "`delFlag` int(11) NOT NULL COMMENT '删除标识 0:未删除、1:已删除'," +
                "`createUserId` int(11) DEFAULT NULL," +
                "`createTime` datetime NOT NULL COMMENT '创建时间'," +
                "`updateUserId` int(11) DEFAULT NULL," +
                "`updateTime` datetime DEFAULT NULL COMMENT '更新时间'," +
                "`administrativeDivisionId` int(11) DEFAULT NULL COMMENT '行政区划ID'";
        String a1 []=a.split(",");
        String sqlColumn="";
        String sqlLeft="";//
        String inertSql="";
        String updateSql="";
        for(int i=0;i<a1.length;i++){
            String a2=a1[i];
            String  a3[]=a2.split("` ");
            String zd = (a3[0]).replaceAll("`","");
            zd=zd.replaceAll("\\/n","");
            String lx=a3[1];
            if(lx.indexOf("int")>=0){
                inertSql+="#{"+zd+",jdbcType=INTEGER},";
                updateSql+=""+zd+" = #{"+zd+",jdbcType=INTEGER},";
            }else if(lx.indexOf("varchar")>=0||lx.indexOf("text")>=0){
                inertSql+="#{"+zd+",jdbcType=VARCHAR},";
                updateSql+=""+zd+" = #{"+zd+",jdbcType=VARCHAR},";
            }else if(lx.indexOf("date")>=0){
                inertSql+="#{"+zd+",jdbcType=TIMESTAMP},";
                updateSql+=""+zd+" = #{"+zd+",jdbcType=TIMESTAMP},";
            }else{
                System.out.println("error:"+zd+" eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
            }
            sqlColumn+=zd+",";
            sqlLeft+="o."+zd+",";
        }
//        sqlColumn= sqlColumn.substring(0,sqlColumn.length()-1);
////        System.out.println(sqlColumn);
////        sqlLeft= sqlLeft.substring(0,sqlLeft.length()-1);
////        System.out.println(sqlLeft);
////        inertSql= inertSql.substring(0,inertSql.length()-1);
////        System.out.println(inertSql);
////        updateSql= updateSql.substring(0,updateSql.length()-1);
////        System.out.println(updateSql);


        String url="http://114.55.171.187:50018/lnztwl/adsj?a=1加好";
        url= url.replace("http://114.55.171.187:50018/lnztwl","http://tms.feiyang56.cn:40264/lnztwl");
        System.out.println(url);




//        Map<String, String> paramsNew = Maps.newHashMap();
//        paramsNew.put("companyCode","M5928");
//        paramsNew.put("passWord", MD5Util.getMD5Code("123456"));
//        paramsNew.put("parentId","4430");
//        List<TbCompany> subCompanyList = new ArrayList<TbCompany>();
//        try{
//            String url="http://localhost:8083/restful/privilegeManager/selectByParentId";
//            String result = HttpClientUtils.post( url, paramsNew, setHeader(), 20000, 20000);
//            if(result!=null){
//                JSONObject j = JSON.parseObject(result);
//                String  object=j.get("object")+"";
//                subCompanyList= JSON.parseArray(object, TbCompany.class);
//            }
//        }catch (Exception e){
//
//        }
//        try{
//           int b =100;//模拟最大总坐标数
//            double mindis=0.0;//起点最近距离
//            List listP= new ArrayList();
//            for(int f=0;f<b;f++){
//                //生成随机坐标数
//                Random random = new Random();
//                int x=random.nextInt(10);
//                int y=random.nextInt(10);
//                Point p = new Point(x, y);
//                listP.add(p);
//            }
//            System.out.println("随机坐标总数:"+listP.size()+"集合："+JSON.toJSONString(listP));
//            List list = new ArrayList();//最近线路集合
//            for(int i=0;i<listP.size();i++){
//                Point p3 =new Point();//最短距离坐标
//                int c=0;
//                for(int j=i+1;j<b;j++){
//                    c=c+1;
//                    Point p1 = (Point) listP.get(i);
//                    Point p2 =  (Point) listP.get(j);
//                    if(c==1){
//                        //每轮第一次进来
//                        mindis=distance(p1,p2);
//                        p3= p2;
//                    }else{
//                        double dis = distance(p1,p2);
//                        if(mindis>dis){
//                            mindis = dis;
//                            p3=p2;
//                        }
//                    }
//                }
//                list.add(p3);
//            }
//            System.out.println("最佳线路总数:"+list.size()+"集合："+JSON.toJSONString(list));
//        }catch (Exception e){
//
//        }

    }

    public static double distance(Point p1,Point p2 ){
        //求两点间最短距离的方法dis  测试使用
        double dis = Math.sqrt(Math.abs((p1.getX() - p2.getX())* (p1.getX() - p2.getX())+(p1.getY() - p2.getY())* (p1.getY() - p2.getY())));
//        System.out.println("两点间的距离是:" + dis);
        // 谷歌地图计算两点间最近距离 GoogleMapHelper.getDistance(Double.valueOf(longitude),Double.valueOf(latitude),gg_lon,gg_lat)
        return dis;
    }

}
